//
//  ZQTopicVoiceView.m
//  BuDeJie
//
//  Created by 仲琦 on 16/4/15.
//  Copyright © 2016年 仲琦. All rights reserved.
//

#import "ZQTopicVoiceView.h"
#import "ZQTopic.h"
#import "ZQSeeBigPictureViewController.h"
#import "UIImageView+Download.h"

@interface ZQTopicVoiceView ()

@property (weak, nonatomic) IBOutlet UILabel *playCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *voiceTimeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ZQTopicVoiceView

-(void)awakeFromNib
{
    self.autoresizingMask = UIViewAutoresizingNone;
    
    self.imageView.userInteractionEnabled = YES;
    
    
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(seeBigPicture)]];
    
    
}

- (void)seeBigPicture
{
    ZQSeeBigPictureViewController *seeBigPicture = [[ZQSeeBigPictureViewController alloc]init];
    seeBigPicture.topic = self.topic;
    [self.window.rootViewController presentViewController:seeBigPicture animated:YES completion:nil];
    
}

- (void)setTopic:(ZQTopic *)topic
{
    _topic = topic;
    
    
    //  先判断, 内存中有没有图片  有图片直接赋值, 如果没有  判断是否wifi连接,
    //  wifi连接下载大图,  wifi没连接 判断 手机是否连接 网络
    //  手机连接了网络,判断用户配置是否下载原图, 如果没有配置 下载小图
    //  手机没有联网查看缓存是否有小图. 有几赋值,没有就赋值占位图
    
    UIImage *placeholderImage = nil;
    
    [self.imageView zq_setImageOriginalImageURL:topic.image1 thumbnailImageURL:topic.image0 placeholderImageURL:placeholderImage completed:nil];
    
    
    
    
    
    if (topic.playcount >= 10000) {
        self.playCountLabel.text = [NSString stringWithFormat:@"%.2f万次播放", topic.playcount / 10000.0];
    }else{
        self.playCountLabel.text = [NSString stringWithFormat:@"%zd次播放", topic.playcount];
    }
    
    self.voiceTimeLabel.text = [NSString stringWithFormat:@"%02zd : %02zd", topic.voicetime/60, topic.voicetime%60];
}
- (IBAction)playVoiceBtnClick:(id)sender {
}

@end
